Java Design Patterns Interview Questions and Answers
Question: What is Singleton design pattern in Java ? write code for thread-safe singleton in Java.Answer: Singleton pattern focus on sharing of expensive object in whole system. Only one instance of a particular class is maintained in whole application which is shared by all modules. Java.lang.Runtime is a classical example of Singleton design pattern. From Java 5 onwards you can use enum to thread-safe singleton. |
Is it helpful?
Yes
No
Most helpful rated by users:
- What is design patterns?
- Can you name few design patterns used in standard JDK library?
- What is Singleton design pattern in Java ? write code for thread-safe singleton in Java.
- What is main benefit of using factory pattern? Where do you use it?
- What is observer design pattern in Java?